package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsInvoiceIntoDto;
import com.sale.goods.domain.vo.GoodsInvoiceIntoVo;
import com.sale.goods.service.IGoodsInvoiceIntoService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @Description 进项税发票
 * @Date 23-07-19
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/invoiceInto")
public class GoodSInvoiceIntoController extends BaseController {

    private final IGoodsInvoiceIntoService goodSInvoiceIntoService;


    /**
     * 获取进项税发票
     */
    //@SaCheckPermission("finance:inItemTax:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsInvoiceIntoDto> list(GoodsInvoiceIntoVo goodSInvoiceIntoVo, PageQuery pageQuery) throws ParseException {
        return goodSInvoiceIntoService.selectInvoiceIntoList(goodSInvoiceIntoVo,pageQuery);
    }

    /**
     * 新增进项税发票
     */
    //@SaCheckPermission("finance:inItemTax:add")
    @Log(title = "进项税发票", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsInvoiceIntoVo goodSInvoiceIntoVo) throws Exception {
        return toAjax(goodSInvoiceIntoService.insertInvoiceInto(goodSInvoiceIntoVo));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{invoiceIntoId}")
    //@SaCheckPermission("finance:inItemTax:query")
    public R getInfo(@PathVariable long invoiceIntoId)
    {
        return R.ok(goodSInvoiceIntoService.selectInvoiceIntoById(invoiceIntoId));
    }

    /**
     * 删除进项税发票
     */
    //@SaCheckPermission("finance:inItemTax:remove")
    @Log(title = "进项税发票", businessType = BusinessType.DELETE)
    @DeleteMapping("/{invoiceIntoId}")
    public R<Void> remove(@PathVariable("invoiceIntoId") Long invoiceIntoId) {
        return toAjax(goodSInvoiceIntoService.deleteInvoiceIntoById(invoiceIntoId));
    }

    /**
     * 修改进项税发票
     */
    //@SaCheckPermission("finance:inItemTax:edit")
    @Log(title = "进项税发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsInvoiceIntoVo goodSInvoiceIntoVo) {
        return toAjax(goodSInvoiceIntoService.updateInvoiceIntoEdit(goodSInvoiceIntoVo));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:inItemTax:submit")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{invoiceIntoId}")
    public R<Void> submitReview(@PathVariable("invoiceIntoId") Long invoiceIntoId) {
        return toAjax(goodSInvoiceIntoService.submitReview(invoiceIntoId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:inItemTax:revoke")
    @Log(title = "撤销审核", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{invoiceIntoId}")
    public R<Void> deleteReview(@PathVariable("invoiceIntoId") Long invoiceIntoId) {
        return toAjax(goodSInvoiceIntoService.deleteReview(invoiceIntoId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("finance:inItemTax:review")
    @Log(title = "审核单据", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsInvoiceIntoVo goodSInvoiceIntoVo) throws Exception {
        return toAjax(goodSInvoiceIntoService.goodSExamineReview(goodSInvoiceIntoVo));
    }

    /**
     * 认证
     */
    //@SaCheckPermission("finance:inItemTax:goodsThe")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @GetMapping("/goodsThe/{invoiceIntoId}")
    public R<Void> goodsThe(@PathVariable("invoiceIntoId") Long invoiceIntoId) {
        return toAjax(goodSInvoiceIntoService.goodsThe(invoiceIntoId));
    }


}
